package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.PrcAddDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.PrcQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.PrcUpdateDTO;
import com.yxw.yxnet_cd_center.customer_service.service.IPrcService;
import com.yxw.yxnet_cd_center.customer_service.vo.PrcVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问题收集管理Controller控制层处理
 *
 * @author xiexuxin
 * @date 2023-09-21
 */

@Slf4j
@Api(value = "问题收集库", tags = "问题收集库")
@RestController
@Validated
@RequestMapping("/v1/problem-collection")
public class PrcController {

    @Autowired
    private IPrcService prcService;

    /**
     * 添加问题
     */
    @ApiOperation("添加问题")
    @PostMapping("/addProblem")
    public BaseResult addProblem(@RequestBody PrcAddDTO prcAddDTO) {
       prcService.addProblem(prcAddDTO);
        return BaseResult.success();
    }

    /**
     * 删除问题
     */
    @ApiOperation("根据id删除问题")
    @PostMapping("/{problemLibId}/deletePrcById")
    public BaseResult remove(@PathVariable Long problemLibId) {
        log.info("开始处理【根据id删除问题】的请求，参数：{}", problemLibId);
        prcService.deletePrcById(problemLibId);
        return BaseResult.success();
    }

    /**
     * 批量删除问题
     */
    @ApiOperation("根据id批量删除问题")
    @PostMapping("/{problemLibIds}/batch-delete")
    public BaseResult batchDelete(@PathVariable List<Long> problemLibIds) {
        log.info("开始处理【根据id批量删除问题】的请求，参数：{}", problemLibIds);
        prcService.deletePrcByIds(problemLibIds);
        return BaseResult.success();
    }

    /**
     * 修改问题
     */
    @ApiOperation("根据id修改问题")
    @PostMapping("{problemLibId}/updatePrc")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "problemLibId", value = "问题ID", required = true, dataType = "long")
    })
    public BaseResult edit( @PathVariable @Range(min = 1, message = "请提交有效的类别ID值！") Long problemLibId,
                            @RequestBody PrcUpdateDTO prcUpdateDTO) {
        log.info("开始处理【根据id修改问题】的请求，ID：{}，新数据：{}", problemLibId,prcUpdateDTO);
        prcService.updatePrc(problemLibId,prcUpdateDTO);
        return BaseResult.success();
    }

    /**
     * 根据id查询问题信息
     */
    @ApiOperation(value = "根据id查询问题信息")
    @GetMapping(value = "/{problemLibId}")
    public BaseResult getInfo(@PathVariable("problemLibId") Long problemLibId) {
        log.info("开始处理【根据id查询问题信息】的请求，ID：{}", problemLibId);
        PrcVO prcVO = prcService.selectPrcById(problemLibId);
        return BaseResult.success(prcVO);
    }

    /**
     * 查询问题列表
     */
    @ApiOperation(value = "查询问题列表")
    @PostMapping("/prcList")
    public BaseResult list() {
        log.info("开始处理【查询问题列表】请求,无参数");
        List<PrcVO> list = prcService.prcList();
        return BaseResult.success(list);
    }

    /**
     * 条件查询问题列表
     */
    @ApiOperation(value = "条件查询问题")
    @PostMapping(value = "/getPrcList")
    public BaseResult<PageVO<PrcVO>> getPrcList(@RequestBody PrcQueryDTO prcQueryDTO) {
        log.info("开始处理【条件查询问题】请求,参数:{}",prcQueryDTO);
        PageVO<PrcVO> pageVo=prcService.getPrcList(prcQueryDTO);
        return ResultHelper.fillWithSuccess(pageVo);
    }

    /**
     * 常见问题收录
     */
    @ApiOperation(value = "常见问题收录")
    @PostMapping(value = "/{problemLibIds}/migrateData")
    public BaseResult migrateData(@PathVariable List<Long> problemLibIds) {
        log.info("开始处理【条件查询问题】请求,参数:{}",problemLibIds);
        prcService.migrateData(problemLibIds);
        return BaseResult.success();
    }

}
